<?php
###############   COPYLEFT GPLv3 LICENSE   ###############
##
## JFX Version 0.2.7
## Website Management Software
## www.jfxcms.com
##
## Copyright 2009 GPLv3 - http://www.opensource.org/licenses/gpl-3.0.html
##
## Anthony Gallon
## oi_antz@hotmail.com
##
## Permission is hereby granted to any person having a copy of this software
## to freely use and modify as required so long as the copyright notices
## and branding remain intact.
##
## Full license details available at http://www.jfxcms.com/license
##
###############   COPYLEFT GPLv3 LICENSE   ###############

/**
 * A drop-menu class for creating a date selection form element
 * @author Anthony Gallon
 * @package  jfx-core-classes
 */


/**
 * A drop-menu class for creating a date selection form element
 * @author Anthony Gallon
 * @package  jfx-core-classes
 */

class JFX_Form_Components_DateSelect_Select extends JFX_Form_Component
{
    /**
     * Contain the options in this drop menu
     * @var array $options
     */
    protected $options = array();

    /**
     * Define the type of object
     * @var string $type
     */
    protected $type = 'DateSelect_Select';

    /**
     * Set some inital values
     * @param string $name
     * @param mixed $value
     */
    public function __construct($name, $value=''){
        $this->id = 'sel'.rand();
        $this->name = $name;
        $this->value = $value;
    }

    /**
     * Add an option to the drop menu
     * @param string $title
     * @param string $value
     * @return object JFX_Form_Components_Option
     */
    public function add($title, $value=''){
        if($value=='')$value = $title;
        $selected = ($this->value.'' == ''.$value) ? true : false;
        $this->options[] = new JFX_Form_Components_Option($title, $value, $selected);
        return $this->options[(count($this->options)-1)];
    }

    /**
     * Get the element as an HTML string
     * @return string $html
     */
    public function render(){
        $disabled = ($this->disabled) ? 'disabled="disabled"' : '';
        $returnString = "\n".'<select name="'.$this->name.'" id="'.$this->getId().'" '.$this->renderParameters().$disabled.'>';
        foreach($this->options as $option){
            $returnString .= "\n  ".$option->render();
        };
        $returnString .= "\n".'</select>'.$this->afterText;
        return $returnString;
    }
}
